﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WyUnity.Data.Query;
using WyUnity.Data.TableMapper;

namespace RFID_Interface.DTO
{
    public class InventoryInfo
    {
        public string StockNumber { get; set; }
        public string ICItemNumber { get; set; }
        public decimal Qty { get; set; }
        public decimal WaitingSendQty { get; set; }
        public string Unit { get; set; }

        public static FieldBase pStockNumber = new Field<InventoryInfo>(p => p.StockNumber);
        public static FieldBase pICItemNumber = new Field<InventoryInfo>(p => p.ICItemNumber);

        public static List<InventoryInfo> Query(string stockNumber, string icitemNumber)
        {
            using (var db = DB.Open())
            using (var dr = db.QueryReader("exec p_QueryInventory @stocknum,@icitemnum", stockNumber, icitemNumber))
            {
                var rlt = new List<InventoryInfo>();
                while (dr.Read())
                {
                    rlt.Add(new InventoryInfo
                    {
                        StockNumber = dr.GetString("StockNumber"),
                        ICItemNumber = dr.GetString("ICItemNumber"),
                        Qty = dr.GetDecimal("Qty"),
                        WaitingSendQty = dr.GetDecimal("WaitingSendQty"),
                        Unit = dr.GetString("Unit")
                    });
                }
                return rlt;
            }
        }

        public static List<InventoryInfo> QueryPDSchema(string stockNumber, string icitemNumber, string iventoryScheme)
        {
            return new List<InventoryInfo>();

            using (var db = DB.Open())
            using (var dr = db.QueryReader("exec p_QueryPDInventory @pdScheme,@stocknum,@icitemnum", iventoryScheme, stockNumber, icitemNumber))
            {
                var rlt = new List<InventoryInfo>();
                while (dr.Read())
                {
                    rlt.Add(new InventoryInfo
                    {
                        StockNumber = dr.GetString("StockNumber"),
                        ICItemNumber = dr.GetString("ICItemNumber"),
                        Qty = dr.GetDecimal("Qty"),
                        Unit = dr.GetString("Unit")
                    });
                }
                return rlt;
            }
        }

    }
}